package com.example.redis.Utils;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 工具类
 */
@Component
public class RedisUtil {
   @Resource
   private RedisTemplate<String,Object> redisTemplate;

   /**
    * 存储数据
    * @param key
    * @param obj
    * @return
    */
   public  boolean set(String key,Object obj){
      ValueOperations<String,Object> ov =redisTemplate.opsForValue();
      ov.set(key,obj);
      return  true;
   }

   /**
    * 获取参数
    * @param key
    * @return
    */
   public Object get(String key){
      ValueOperations<String,Object> ov  =redisTemplate.opsForValue();
       return  ov.get(key);
   }

}
